package com.springboot.demo.async;

import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @Description： 异步任务
 * @Date： Created in 2021/12/22
 * @author： jianbin.lei
 * @Auto： <a href="mailto:493168771@qq.com">jianbin.lei</a>
 */
@Component
public class AsyncTask {

        public static Random random =new Random();

        public void doOne() throws Exception {
            System.out.println("任务一Start");
            long start = System.currentTimeMillis();
            //随机sleep
            Thread.sleep(random.nextInt(10000));
            long end = System.currentTimeMillis();
            System.out.println("任务一：耗时：" + (end - start) + "毫秒");
        }

        public void doTwo() throws Exception {
            System.out.println("任务二Start");
            long start = System.currentTimeMillis();
            //随机sleep
            Thread.sleep(random.nextInt(10000));
            long end = System.currentTimeMillis();
            System.out.println("任务二：耗时：" + (end - start) + "毫秒");
        }

        public void doThree() throws Exception {
            System.out.println("任务三Start");
            long start = System.currentTimeMillis();
            //随机sleep
            Thread.sleep(random.nextInt(10000));
            long end = System.currentTimeMillis();
            System.out.println("任务三：耗时：" + (end - start) + "毫秒");
        }
}
